import {Form, Icon, Input, Button, Checkbox, message} from 'antd';
import React from 'react';
import 'antd/dist/antd.css';
import './login.css';
import {login} from '../../util/requestUtil'

const localStorage = window.localStorage;

class NormalLoginForm extends React.Component {
    handleSubmit = e => {
        console.log(this.props)
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            const value = {
                username: values['username'],
                password: values['password'],
            }
            if (!err) {
                login('/oauth/token', value)
            }
        });
    };

    render() {
        const {getFieldDecorator} = this.props.form;
        return (
            <div className="root">
                <div className="login">
                    <h2 style={{marginTop:"10px"}}>时政平台后台管理系统</h2>
                    <Form onSubmit={this.handleSubmit} className="login-form">
                        <Form.Item>
                            {getFieldDecorator('username', {
                                rules: [{required: true, message: '请输入用户名!'}],
                            })(
                                <Input
                                    prefix={<Icon type="user" style={{color: 'rgba(0,0,0,.25)'}}/>}
                                    placeholder="Username"
                                />,
                            )}
                        </Form.Item>
                        <Form.Item>
                            {getFieldDecorator('password', {
                                rules: [{required: true, message: '请输入密码!'}],
                            })(
                                <Input
                                    prefix={<Icon type="lock" style={{color: 'rgba(0,0,0,.25)'}}/>}
                                    type="password"
                                    placeholder="Password"
                                />,
                            )}
                        </Form.Item>
                        <Form.Item>
                            <a className="login-form-forgot" href="">
                                忘记密码
                            </a>
                            <Button type="primary" htmlType="submit" className="login-form-button">
                                登录
                            </Button>

                        </Form.Item>
                    </Form>
                </div>
            </div>
        );
    }
}

const WrappedNormalLoginForm = Form.create()(NormalLoginForm);

export default WrappedNormalLoginForm;